package zzz.a;

/*
 * testing
 */

public class Recursive {

	public static void dec(int n) {
		System.out.println(n + " ");
		if (n == 1) {
			return;
		}
		dec(n - 1);
		
	}
	
	public static void inc(int n) {
		if (n > 1) {
			inc(n - 1);
		}
		System.out.println(n + " ");

	}

	public static long factorial(int N) {
		if (N <= 1) {
			return 1;
		}
		return N * factorial(N - 1);
	}

	public static long fibu(int N) {
		if (N == 0) {
			return 0;
		}
		if (N == 1) {
			return 1;
		}
		return (fibu(N - 1) + fibu(N - 2));
	}
	
	public static int ggT(int p, int q) {
		if (q == 0) {
			return p;
		}
		return ggT(q, p % q);
	}

	public static int ggTnRown(int p, int q) {
		int a, b, result = 0;
		a = Math.max(p, q);
		b = Math.min(p, q);
		for (int n = b; n > 1; n--) {
			if (((b % n) == 0) & ((a % n) == 0)) {
				result = n;
				break;
			}
		}
		return result;
	}
	
	public static int ggTnR(int p, int q) {
		int temp = 0;
		while (q != 0) {
			temp = p;
			p = q;
			q = temp % p;
		}
		return p;
	}
	
	public static void main(String[] args) {
		int n = Integer.parseInt(args[0]);
		int m = Integer.parseInt(args[1]);
		// dec(40);
		// inc(40);
		// for (int i = 1; i < 20; i++) {
		// System.out.println(i + "! = " + factorial(i));
		// }
		System.out.println(ggT(n, m));
		System.out.println(ggTnR(n, m));
		System.out.println(ggTnRown(n, m));
	}
	
}